package com.lsq.tucao.express.controller;

import com.lsq.tucao.express.bean.po.UserLike;
import com.lsq.tucao.express.response.JsonResult;
import com.lsq.tucao.express.service.UserLikeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user-like")
public class UserLikeController {

    @Autowired
    private UserLikeService userLikeService;

    /**
     * @author lsq
     * @description 根据userId，分页查询用户点赞的吐槽或鸡汤
     * @param current 页码
     * @param size 每页条数
     * @param userId 用户id
     * @param sort 分类，0->搜索吐槽 ；1->搜索鸡汤
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/22 17:26
     */
    @GetMapping("/page")
    public JsonResult getTucaoOrHeartLikeByUserId(@RequestParam(required = false,defaultValue = "1") Integer current,
                                                  @RequestParam(required = false,defaultValue = "10") Integer size,
                                                  @RequestParam Long userId,
                                                  @RequestParam Integer sort){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("userId:{}",userId);
        log.debug("sort:{}",sort);

        return userLikeService.getTucaoOrHeartLikeByUserId(current, size, userId, sort);
    }

    /**
     * @author lsq
     * @description 增加用户的鸡汤点赞或吐槽点赞内容，给吐槽或鸡汤的点赞数加一
     * @param userLike 点赞实体类
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/22 17:27
     */
    @PostMapping("like")
    public JsonResult likeTucaoOrHeart(@RequestBody UserLike userLike){
        log.debug("userLike:{}",userLike);

        return userLikeService.likeTucaoOrHeart(userLike);
    }

    /**
     * @author lsq
     * @description 取消对某条吐槽或鸡汤的点赞
     * @param userId 用户id
     * @param tucaoOrHeartId 吐槽id或鸡汤id
     * @param sort 分类；0->吐槽；1->鸡汤
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/22 19:50
     */
    @PostMapping("cancel-like")
    public JsonResult cancelLikeTucaoOrHeart(@RequestParam Long userId,
                                             @RequestParam Long tucaoOrHeartId,
                                             @RequestParam Integer sort){
        log.debug("userId:{}",userId);
        log.debug("tucaoOrHeartId:{}",tucaoOrHeartId);
        log.debug("sort:{}",sort);

        return userLikeService.cancelLikeTucaoOrHeart(userId, tucaoOrHeartId, sort);
    }

    /**
     * @author lsq
     * @description 通过userId和tucaoId，判断该用户是否对这条吐槽进行过点赞操作
     * @param userId 用户id
     * @param tucaoOrHeartId 吐槽id
     * @param sort 分类；0->吐槽；1->鸡汤
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/22 18:30
     */
    @GetMapping("/judge")
    public JsonResult judgeIsLike(@RequestParam Long userId,
                                  @RequestParam Long tucaoOrHeartId,
                                  @RequestParam Integer sort){
        log.debug("userId:{}",userId);
        log.debug("tucaoOrHeartId:{}",tucaoOrHeartId);
        log.debug("sort:{}",sort);

        return userLikeService.judgeIsLike(userId, tucaoOrHeartId, sort);
    }

}
